{include file="member.header.html"}
{include file="title.html"}
{include file=member.submenu.html}

<script type="text/javascript">
//<!CDATA[
    $(function() {
        $('#mix_form').validate({
            errorPlacement: function(error, element) {
                $(element).next('.field_notice').hide();
                $(element).after(error);
            },
            success: function(label) {
                label.addClass('validate_right').text('OK!');
            },
            onkeyup: false,
            rules: {
                mix_name: {
                    required: true,
                    byteRange: [3, 30, '{$charset}'],
                },
                goods_id: {
                    required: true,
                }
            },
            messages: {
                mix_name: {
                    required: '{$lang.fill_mix_name}',
                    byteRange: '{$lang.mix_name_limit}'
                },
                goods_id: {
                    required: '{$lang.fill_goods}'
                },
            }
        });
        // 商品分类
        gcategoryInit("gcategory");
    });
    function gs_callback() {
    }

    function searchGoods() {
        var cate_id = $("#cate_id").val() ? parseInt($("#cate_id").val()) : 0;
        var store_id = parseInt({$store_id});
        var mix_items = '{$mix_items}';
        $.getJSON('index.php?app=seller_mix&act=query_goods_info', {
            'cate_id': cate_id,
            'store_id': store_id,
            'mix_items': mix_items
        },
        function(data) {
            if (data.done) {
                var goods_list = data.retval;
                $('select[name="selectleft"]').html('');
                $.each(goods_list, function(i, item) {
                    $('select[name="selectleft"]').append('<option value="' + item.goods_id + '">' + item.goods_name + '</option>');
                });
            }
        });
    }
    function select_all()
    {
        $("#SelectRight").find("option").each(function() {
            $(this).attr('selected', true);
        });
        return true;
    }
//]]>
</script>


<form method="post" id="mix_form" onsubmit="select_all();">
<ul class="form_content">
    <li>
        <h3>{$lang.mix_name}</h3>
        <p><input type="text" name="mix_name" value="{$mix.mix_name|escape}" /></p>
    </li>
    <li>
        <h3>{$lang.mix_desc}</h3>
        <p><textarea name="mix_desc">{$mix.mix_desc|escape}</textarea></p>
    </li>
    <li>
        <h3>{$lang.mix_main_goods}</h3>
        <p>
            <input class="white_btn" gs_id="goods_id" gs_name="goods_name" gs_callback="gs_callback" gs_title="gselector" gs_width="100%" gs_type="store" gs_store_id="{$store_id}" ectype="gselector" type="text" name="goods_name" id="goods_name" value="{$mix.nav_goods_name|escape}"  />
            <input type="hidden" id="goods_id" name="goods_id" value="{$mix.nav_goods_id}" />
        </p>
    </li>
    <li>
        <h3>{$lang.sgcategory}</h3>
        <p>
            <select name="sgcate_id[]" class="sgcategory">
                <option value="0">{$lang.select_pls}</option>
                {html_options options=$sgcategories}
            </select>
            <input type="hidden" id="cate_id" name="cate_id" value="" class="mls_id" />
            <input type="hidden" name="cate_name" value="" class="mls_names" />
        </p>
    </li>
    <li>
        <p>
            <input type="button" class="red_btn" onclick="javascript:searchGoods();" value=" {$lang.search} ">
        </p>
    </li>
    <li>
        <p>
            <select multiple="multiple" size="4" name="selectleft" id="SelectLeft" ondblclick="moveOption($('#SelectLeft'), $('#SelectRight'))"></select>
        </p>
        <p>
            <input type="button" value="加入搭配销售" onclick="moveOption($('#SelectLeft'), $('#SelectRight'))" class="red_btn"/>
        </p>
        <p>
            <input type="button" value="移出搭配销售" onclick="moveOption($('#SelectRight'), $('#SelectLeft'))" class="red_btn"/>
        </p>
        <p>
            <select multiple="multiple" size="4" name="selectright[]" id="SelectRight" ondblclick="moveOption($('#SelectRight'), $('#SelectLeft'))">
                <!--{foreach from=$goods_list item=goods}-->
                <option value="{$goods.goods_id}">{$goods.goods_name|escape}</option>
                <!--{/foreach}-->
            </select>
        </p>
    </li>
    <li>
        <p><input type="submit" class="red_btn" value="{$lang.submit}" /></p>
    </li>

</ul>
</form>

<script language="javascript">
    //上移
    function moveUp(obj)
    {
        
                if (!$("option:selected", obj).val()) {
            alert('{$lang.pls_select_option}');
            return false;
        }
        if ($("option:selected", obj).length > 1) {
            alert('{$lang.such_op_only_item}');
            return false;
        }
        var SourceIndex = $("option:selected", obj).attr("index");
        var TargetIndex = SourceIndex - 1;
        var SourceVal = $("option:selected", obj).val();
        var SourceText = $("option:selected", obj).text();
        var TargetVal = $("option[index='" + TargetIndex + "']", obj).val();
        var TargetText = $("option[index='" + TargetIndex + "']", obj).text();
        $("option:selected", obj).val(TargetVal).text(TargetText).attr('selected', false);
        $("option[index='" + TargetIndex + "']", obj).val(SourceVal).text(SourceText).attr('selected', true);
    }
    //下移
    function moveDown(obj)
             {
        if (!$("option:selected", obj).val()) {
            alert('{$lang.pls_select_option}');
            return false;
        }
        if ($("option:selected", obj).length > 1) {
            alert('{$lang.such_op_only_item}');
            return false;
        }
        var SourceIndex = $("option:selected", obj).attr("index");
        var TargetIndex = SourceIndex + 1;
        var SourceVal = $("option:selected", obj).val();
        var SourceText = $("option:selected", obj).text();
        var TargetVal = $("option[index='" + TargetIndex + "']", obj).val();
        var TargetText = $("option[index='" + TargetIndex + "']", obj).text();
        $("option:selected", obj).val(TargetVal).text(TargetText).attr('selected', false);
        $("option[index='" + TargetIndex + "']", obj).val(SourceVal).text(SourceText).attr('selected', true);
        }
    //移动
    function moveOption(obj1, obj2)
    {
        $("option:selected", obj1).each(function(i) {
            var OptionVal = $(this).val();
            var OptionText = $(this).text();
            $("<option value='" + OptionVal + "'>" + OptionText + "</option>").appendTo($(obj2)).attr('selected', true);
            $(this).remove();
        });
    }
    //置顶
    function  moveTop(obj)
    {
        if (!$("option:selected", obj).val()) {
            alert('{$lang.pls_select_option}');
            return false;
        }
        if ($("option:selected", obj).length > 1) {
            alert('{$lang.such_op_only_item}');
            return false;
        }
        var SourceVal = $("option:selected", obj).val();
        var SourceText = $("option:selected", obj).text();
        var TargetVal = $("option[index='0']", obj).val();
        var TargetText = $("option[index='0']", obj).text();
        $("option:selected", obj).val(TargetVal).text(TargetText).attr('selected', false);
        $("option[index='0']", obj).val(SourceVal).text(SourceText).attr('selected', true);
    }
    //置底
    function  moveBottom(obj)
    {
        if (!$("option:selected", obj).val()) {
            alert('{$lang.pls_select_option}');
            return false;
        }
        if ($("option:selected", obj).length > 1) {
            alert('{$lang.such_op_only_item}');
            return false;
        }
        var SourceVal = $("option:selected", obj).val();
        var SourceText = $("option:selected", obj).text();
        var TargetVal = $("option:last", obj).val();
        var TargetText = $("option:last", obj).text();
        $("option:selected", obj).val(TargetVal).text(TargetText).attr('selected', false);
        $("option:last", obj).val(SourceVal).text(SourceText).attr('selected', true);
    }
</script>


{include file=member.page.bottom.html}
{include file="footer.html"}